local sk__lihun = fk.CreateSkill {

  name = "sk__lihun",

  tags = {},

}



sk__lihun:addEffect(fk.TurnEnd, {
  name = "sk__lihun",
  anim_type = "control",
  events = { fk.TurnEnd },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sk__lihun.name)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1,
      "#sk__lihun-choose", sk__lihun.name, true)
    if #to > 0 then
      event:setCostData(self, to[1])
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(event:getCostData(self))
    room:setPlayerMark(to, "@@sk__lihun", player.id)
    to:gainAnExtraTurn()
  end,
})
sk__lihun:addEffect(fk.BeforeTurnStart, {
  can_refresh = function(self, event, target, player, data)
    return target:getMark("@@sk__lihun") == player.id or target:getMark("@@sk__lihun") == 0
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if target:getMark("@@sk__lihun") == player.id then
      player:control(target)
      room:handleAddLoseSkills(target, "sk__lihun_active&", nil, false, true)
    else
      room:setPlayerMark(target, "@@sk__lihun", 0)
      room:handleAddLoseSkills(target, "-sk__lihun_active&", nil, false, true)
      target:control(target)
    end
  end,
})
sk__lihun:addEffect(fk.TurnEnd, {
  can_refresh = function(self, event, target, player, data)
    return target:getMark("@@sk__lihun") == player.id
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(target, "@@sk__lihun", 0)
    room:handleAddLoseSkills(target, "-sk__lihun_active&", nil, false, true)
    target:control(target)
  end,
})

sk__lihun:addEffect("targetmod", {
  name = "#sk__lihun_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return card and scope == Player.HistoryPhase and player:getMark("@@sk__lihun") ~= 0
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and player:getMark("@@sk__lihun") ~= 0
  end,
})

return sk__lihun
